﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UndoRedo
{
    /// <summary>
    /// Simple implementation of <see cref="ChangeInformation"/> that provides an easy way for implementing undo/redo functionality.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ActionChangeInformation<T> : IChangeInformation<T>
    {
        private readonly Action<T> _undoAction;
        private readonly Action<T> _redoAction;

        public ActionChangeInformation(Action<T> undoAction, Action<T> redoAction)
        {
            if (undoAction == null)
                throw new NullReferenceException("undoAction");
            if (redoAction == null)
                throw new NullReferenceException("redoAction");

            this._undoAction = undoAction;
            this._redoAction = redoAction;
        }

        public void Undo(T target)
        { this._undoAction(target); }

        public void Redo(T target)
        { this._redoAction(target); }
    }
}